$value) { $this->variable_main[':('.$key.')'] = $value; } } } else { if (is_array($var)) { foreach ($var as $key=>$value) { $this->variable_block[$main_block]['@('.$key.')'] = $value; } } } } function replace_var($block,$string) { global $row; if (preg_match_all('/\$\(([^\$])+\)\$/',$string,$array_match))//нашли вызов функции { foreach ($array_match[0] as $pattern) { $pattern = substr($pattern,2,strlen($pattern)-4); $function = split("\.",$pattern); $funct = $function[0]; $array_par = array(); $array_p = array(); foreach ($function as $key=>$arg_p) { if ($key>0) { $array_p[] = $arg_p; $first_char = substr($arg_p,0,1); switch ($first_char) { case '@': $arg_p=@$this->variable_block[$block][$arg_p];//меняем на локальную переменную break; case ':': $arg_p=@$this->variable_main[$arg_p];//меняем на глобальную переменную break; case '{': $arg_p=@$row[strtolower(substr($arg_p,1,strlen($arg_p)-2))];//меняем на переменную из данных break; } $array_par[] = $arg_p; } } $string = preg_replace("/\\$\(".$funct.".".preg_quote(implode(".",$array_p))."\)\\$/",call_user_func_array($funct,$array_par),$string); } } if (preg_match_all('/:\([^(.+)\)]+\)/',$string,$array_match))//нашли глобальную переменную { for ($a = 0; $a < count($array_match[0]); $a++) { $word = preg_quote($array_match[0][$a],'('); if (key_exists($array_match[0][$a],$this->variable_main)) { $string = preg_replace("/$word/",$this->variable_main[$array_match[0][$a]],$string); } } } if (preg_match_all('/@\(L_[^(.+)\)]+\)/',$string,$array_match))//нашли локальную переменную { for ($a = 0; $a < count($array_match[0]); $a++) { $word = preg_quote($array_match[0][$a],'('); if (@key_exists($array_match[0][$a],$this->variable_block['language'])) { $string = preg_replace("/$word/",$this->variable_block['language'][$array_match[0][$a]],$string); } } } if (preg_match_all('/@\([^(.+)\)]+\)/',$string,$array_match))//нашли локальную переменную { for ($a = 0; $a < count($array_match[0]); $a++) { $word = preg_quote($array_match[0][$a],'('); error_reporting(0); if (key_exists($array_match[0][$a],$this->variable_block[$block])) { $string = preg_replace("/$word/",$this->variable_block[$block][$array_match[0][$a]],$string); } } } if ((preg_match_all("/\{[^(.+)\}]+\}/",$string,$array_match)) and (is_array($row)))//нашли переменную из набора данных для блока { for ($a = 0; $a < count($array_match[0]); $a++) { $key_match = strtolower(preg_replace('/[{}]/','',$array_match[0][$a])); if (key_exists($key_match,$row)) { $string = preg_replace("/\{".strtoupper($key_match)."\}/",htmlspecialchars_decode($row[$key_match]),$string); } else { $string = preg_replace("/\{".strtoupper($key_match)."\}/",'',$string); } } } if (preg_match('//',$string,$var_array)) { $block = $var_array[1]; if (is_array($this->block_template[$block]['compiled_code'])) { $string = preg_replace('//',implode("",$this->block_template[$block]['compiled_code']),$string); } } return $string; } function parse_row($string,$block,$string_array) { global $row; $data = @$this->variable_block[$block]['data']; if (is_array($data)) { $end_row = 0; $cols_show = 0; for ($row_n=1;$row_n<=count($data);$row_n++) { $row = @$this->variable_block[$block]['data'][$row_n-1]; $this->variable_block[$block]['@(NUM_ROW)']=$row_n; $col_start = 0; $col_end = 0; $counter = 0;//счетчик уровней $if_stared = 1; $need_row = 1; if (@$cols_show==0) { $end_row = 0; } $level_condition = ''; $level_condition = array(); $level_condition[0][0]=1; foreach ($string_array as $string_row_temp) { if (preg_match('//',$string_row_temp,$tag))//управляющий оператор { $tags = $tag[1]; if ((preg_match('/ IF /',$tags))) { $true = false; $tags = $this->replace_var($block,$tags); $counter++; @eval($tags.' $true = true;'); if (($true==true) and ($level_condition[$counter-1][count($level_condition[$counter-1])-1]===1))//выполняем все до ENDIF или ELSEIF { $need_row = 1; $level_condition[$counter][] = 1; } else { $need_row = 0; $level_condition[$counter][] = 0; } } elseif (preg_match('/ ENDIF /',$tags)) { unset($level_condition[$counter]); $counter--; $need_row = $level_condition[$counter][count($level_condition[$counter])-1]; } elseif (preg_match('/ ELSEIF /',$tags)) { $tags = $this->replace_var($block,$tags); $true = false; @eval(preg_replace('/ELSE/','',$tags).' $true = true;'); if (($true==true) and (max($level_condition[$counter])===0) and (($level_condition[$counter-1][count($level_condition[$counter-1])-1])===1))//выполняем все до ENDIF или ELSEIF { $need_row = 1; $level_condition[$counter][] = 1; } else { $need_row = 0; $level_condition[$counter][] = 0; } } } if (($need_row==1) and (!preg_match('/ ENDIF /',$tags)) and (!preg_match('/ ELSEIF /',$tags)) and (!preg_match('/ IF /',$tags))) { if (preg_match_all('//s',$string_row_temp,$col_string))//нашли вывод колонок { $count_col = @$col_string[1][0]>0?$col_string[1][0]:1;//количество колонок $col = $col_string[2][0];//содержимое колонки для завершения $col_start = 1; } elseif (preg_match('//s',$string_row_temp))//вывод колонок завершен { $col_end = 1; } else//добавляем строку в вывод если строка не служебная { if (!preg_match('/COL/',$tags)) { if (($col_start==1) and ($col_end==0))//Цикл внутри колонки { @$res_string_array['col'].=$this->replace_var($block,$string_row_temp); $cols_show++; } elseif(($col_end==1) and (@$end_row!=1))//Цикл колонок закончился { @$res_string_array['after_col'].=$this->replace_var($block,$string_row_temp); } elseif(@$end_row!=1)//До цикла колонок { @$res_string_array['before_col'].=$this->replace_var($block,$string_row_temp); } } if ($cols_show==$count_col) { @$res_string_array['cols'] .= @$res_string_array['before_col'].@$res_string_array['col'].@$res_string_array['after_col']; $cols_show = 0; @$res_string_array['col'] = ''; @$res_string_array['after_col'] = ''; @$res_string_array['before_col'] = ''; //$end_row = 1; } } } $tags=''; } if ($count_col>0) { $end_row = 1;//строка закончилась } } //записи закончились //формируем конечную строку if ($count_col>0)//добавляем пустые колонки по необходимости { $a_a = $count_col-$cols_show; for ($a=1;$a<=$a_a;$a++) { @$dop_col .= $col; } if ($dop_col!='') { $dop_col = $dop_col.@$res_string_array['after_col']; } } $string_row = @$res_string_array['cols'].@$res_string_array['before_col'].@$res_string_array['col'].@$dop_col; return @$string_row; } else { return implode('',$string_array); } } function parse_template($block,$var) { $data = $this->variable_block[$block]['data']; $rules = $this->variable_block[$block]['parent_rules']; $this->block_template[$block]['compiled_code'] = array(); if (is_array($data)) { //есть данные $this->variable_block[$block]['@(EMPTY)']=0; } else { //нет данных $this->variable_block[$block]['@(EMPTY)']=1; } $need_row = 1; $row_start = 0; $row_close = 0; $repeat_code = ''; if (!is_array($var['source_code'])) { $this->block_template[$block]['source_code'][] = "Указанный блок не найден"; $var['source_code'][] = "Указанный блок не найден"; } $level_condition = ''; $level_condition = array(); $level_condition[0][0]=1; $counter=0; foreach ($var['source_code'] as $string) { if ((preg_match('//',$string,$tag)) and ($row_start != 1))//управляющий оператор { $tags = $tag[1]; if ((preg_match('/ IF /',$tags))) { $true = false; $tags = $this->replace_var($block,$tags); $counter++; @eval($tags.' $true = true;'); if (($true==true) and ($level_condition[$counter-1][count($level_condition[$counter-1])-1]===1))//выполняем все до ENDIF или ELSEIF { $need_row = 1; $level_condition[$counter][] = 1; } else { $need_row = 0; $level_condition[$counter][] = 0; } } elseif (preg_match('/ ENDIF /',$tags)) { unset($level_condition[$counter]); $counter--; $need_row = $level_condition[$counter][count($level_condition[$counter])-1]; } elseif (preg_match('/ ELSEIF /',$tags)) { $tags = $this->replace_var($block,$tags); $true = false; @eval(preg_replace('/ELSE/','',$tags).' $true = true;'); if (($true==true) and (max($level_condition[$counter])===0) and (($level_condition[$counter-1][count($level_condition[$counter-1])-1])===1))//выполняем все до ENDIF или ELSEIF { $need_row = 1; $level_condition[$counter][] = 1; } else { $need_row = 0; $level_condition[$counter][] = 0; } } } if (($need_row==1) and (!preg_match('/ ENDIF /',$tags)) and (!preg_match('/ ELSEIF /',$tags)) and (!preg_match('/ IF /',$tags))) { //если встретим ROW начинаем брать данные if (preg_match('//',$string,$tag))//начинается строка { $row_start = 1; } elseif (preg_match('//',$string,$tag))//кончилась строка { $row_start = 0; $row_close = 1; } if (($row_start == 1) and ($row_close != 1) and (!preg_match('//',$string))) { @$repeat_code.= $string; $repeat_code_array[] = $string; } elseif (($row_close == 1) and (@$repeat_code!='')) { $string = $this->parse_row(@$repeat_code,$block,@$repeat_code_array); $this->block_template[$block]['compiled_code'][]=$this->replace_var($block,$string); $row_close = 0; $row_start = 0; } elseif (!preg_match('//',$string)) { $string = $this->replace_var($block,$string); $this->block_template[$block]['compiled_code'][]=$string; } } $tags=''; } } function parce_main_template() { if (is_array($this->main_template['source_code'])) { foreach ($this->main_template['source_code'] as $string) { $this->main_template['compiled_code'][] = $this->replace_var('default',$string).""; } } } function show_html() { if (is_array($this->main_template['compiled_code'])) { foreach ($this->main_template['compiled_code'] as $string) { echo $string; } } } function load_data_block($block,$var) { global $current_config,$config_engine,$table_prefix_engine,$user,$my_engine_base,$num_page,$in_page; //формирование запроса для блока if ($current_config['DEFAULT_BLOCK']==$block)//текущий блок является центральным { $mane = 1; } if ($var['block_var']['data'][0]['query'])//есть запрос для блока { $temp_query = $var['block_var']['data'][0]['query']; if (($var['block_var']['data'][0]['meta']!='') and ($mane==1)) { $this->variable_main[':(META)'] = $var['block_var']['data'][0]['meta']; } if (empty($temp_query)) { //сваливаемся с ошибкой } $temp_limits = $var['block_var']['data'][0]['limits']; $temp_query = preg_replace('/\|(.+)\|/',"`".$table_prefix_engine.$current_config['LANGUAGE']."_".$var['block_var']['data'][0]['table']."`",$temp_query); $use_query = explode("*******",$temp_query); $use_fields = $use_query[0];//поля preg_match('/select (.*) from/',$use_fields,$ff); $use_sort = $use_query[1];//сортировка $user_rules = $my_engine_base->get_user_rules($block,$user->data['user_id'],$user->data['id_group'],''); if (($user->data['is_registered']) and ($user_rules['change'] == 1)) { $active = '';//выводим все } else { $active = ' and (active = 1) ';//выводим только активные } $use_folder_as_item = $var['block_var']['data'][0]['use_folder_as_item']; if ($mane == 1) { if (($current_config['ITEM']=='index') or ($use_folder_as_item==1))//если нет элемента для вывода (в корне блока например) { $current_config['FOLDER']=1; $FOLDER=1; $this->variable_main[':(FOLDER)']=1; $this->variable_main[':(PARENT_ID_CURITEM)']=-1; } else { //определяем является ли папкой выводимый элемент $row = $my_engine_base->get_rowset($current_config['LANGUAGE'].'_'.$var['block_var']['data'][0]['table'],'*','where id = \''.$current_config['ITEM'].'\''); if (!is_array($row['data'])) { $current_config['FOLDER']=-1; $current_config['PARENT_ID_CURITEM']=-1; $current_config['PARENT_TITLE_CURITEM']=''; } else { $current_config['FOLDER']=@$row['data'][0]['folder']; $current_config['PARENT_ID_CURITEM']=@$row['data'][0]['parent_id']; $current_config['PARENT_TITLE_CURITEM']=@$row['data'][0]['title']; } $FOLDER=$current_config['FOLDER']; $this->variable_main[':(FOLDER)']=$FOLDER; $this->variable_main[':(PARENT_ID_CURITEM)']=$current_config['PARENT_ID_CURITEM']; $this->variable_main[':(PARENT_TITLE_CURITEM)']=$current_config['PARENT_TITLE_CURITEM']; } } else { $FOLDER=1; $this->variable_main[':(FOLDER)']=$FOLDER; } if ($mane==1) { if (($current_config['ITEM']=='index') and ($current_config['FOLDER']==1))//не определен элемент и находимся не в папке { $where = " where (parent_id = 0) $active "; } elseif((@$current_config['ITEM']!='index') and ($mane == 1) and ($current_config['FOLDER'] > 0) and ($use_folder_as_item==1))//определен элемент, мы в центральном блоке, и выводим папку, и вывод определен как для элемента { $where = " where (id = '".$current_config['ITEM']."') $active "; } elseif((@$current_config['ITEM']!='index') and ($mane == 1) and ($current_config['FOLDER'] > 0))//определен элемент, мы в центральном блоке, и выводим папку { $where = " where (parent_id = '".$current_config['ITEM']."') $active "; } elseif (($mane == 1) and (@$current_config['ITEM']!='index'))//мы в центральном блоке и выводим конкретный элемент { $where = " where (id = '".$current_config['ITEM']."') $active "; } } else { $where = " where (parent_id = 0) $active "; } $in_page = $config_engine['IN_PAGE'];//количество элементов на странице по умолчанию //определяем лимиты если нужны $use_limits = explode('||',$var['block_var']['data'][0]['limits']); foreach ($use_limits as $key=>$val) { $use_limits[$key] = explode('***',$val); } foreach ($use_limits as $key=>$val) { eval('if('.$FOLDER.' '.$use_limits[$key][0].' '.$use_limits[$key][1].') { $in_page = '.$use_limits[$key][2].'; }'); } $begin = 0; if ($mane==1) { //вычисляем с какой записи и сколько выбирать $begin = $num_page*@$in_page; if (empty($begin)) { $begin = 0; } } //формируем конечный запрос $query = $use_fields; //добавляем сортировку $query .= @$where.@$use_sort; $query_news = $query;//запоминаем запрос для постраничного вывода $query .= ' limit '.@$begin.",".@$in_page; $this->block_template[$block]['f_query'] = $query; $this->block_template[$block]['f_query_news'] = $query_news; if ($mane==1) { $config_engine['META_TAGS']=$var['block_var']['data'][0]['meta']; if (is_array($current_config['PARENT_ITEM'])) { $parent = end($current_config['PARENT_ITEM']); } else { $parent = null; } } else { $parent = null; } if (is_array(@$ff)) { $field = @$ff[1]?$ff[1]:'*'; } $this->variable_block[$block] = array_merge($this->variable_block[$block],$my_engine_base->get_rowset($current_config['LANGUAGE'].'_'.$var['block_var']['data'][0]['table'],$field,@$where.@$use_sort.' limit '.@$begin.",".@$in_page,$user->data,$var['block_var']['data'][0]['name'],$parent)); } else { //????????????????????????????????нету запроса } } function load_main_template($file_name,$theme)//загрузка основного шаблона { global $my_engine_base; if (($file_name) and (file_exists($file_name))) { $source_code = file($file_name); $this->load_header_var(); $source_code = $this->pre_parse_main($source_code); foreach ($source_code as $string) { if (preg_match_all('/:\([^(.+)\)]+\)/',$string,$array_match)) { for ($a = 0; $a < count($array_match[0]); $a++) { $word = preg_quote($array_match[0][$a],'('); if (key_exists($array_match[0][$a],$this->variable_main)) { $string = preg_replace("/$word/",$this->variable_main[$array_match[0][$a]],$string); } } } if (preg_match('//',$string,$var_array)) { $block = $var_array[1]; //получаем переменные(запрос, базовые настройки) из базы для блока $query = $my_engine_base->get_rowset('blocks','*',' where name = \''.$block.'\' limit 1'); $this->block_template[$block]['block_var'] = $query; $this->load_block_template($block,ROOT_PATH.'/template/'.$theme.'/templ/'.$query['data'][0]['template'],$theme); } if (preg_match('/@{(.*)}=(.*);/',$string,$var_array)) { $this->variable_main[':('.$var_array[1].')']=$var_array[2]; } else { $this->main_template['source_code'][]=$string; } } //$this->load_data_block(); } else { //указанного шаблона нет } } function pre_parse_main($source_code) { $need_row=1; foreach ($source_code as $key=>$string) { if (preg_match('//',$string,$tag))//управляющий оператор { $tags = $tag[1]; if (preg_match('/ IF /',$tags)) { $tags = $this->replace_var('default',$tags); eval($tags.' $true = true;'); if ($true==true) { $if_stared = 1;//выполняем все до ENDIF или ELSEIF $need_row = 1; } else { $if_stared = 0; $need_row = 0; } } elseif ((preg_match('/ ELSEIF /',$tags)) and ($if_stared == 1)) { $need_row = 0; } elseif (preg_match('/ ENDIF /',$tags)) { $need_row = 1; } elseif ((preg_match('/ ELSEIF /',$tags)) and ($if_stared == 0)) { $tags = $this->replace_var('default',$tags); eval(preg_replace('/ELSE/','',$tags).' $true = true;'); if ($true==true) { $if_stared = 1;//выполняем все до ENDIF или ELSEIF $need_row = 1; } else { $if_stared = 0; $need_row = 0; } } } if (($need_row==1) and (!preg_match('/ ENDIF /',$tags)) and (!preg_match('/ ELSEIF /',$tags)) and (!preg_match('/ IF /',$tags))) { $src[] = $this->replace_var('default',$string).""; } $tags=''; } return @$src; } function load_block_template($block,$file_name,$theme)//загрузка шаблонов для блоков { global $my_engine_base; if (($file_name) and (file_exists($file_name)) and (is_file($file_name))) { $source_code = file($file_name); $this->variable_block[$block] = array(); foreach ($source_code as $string) { if (preg_match_all('/:\([^(.+)\)]+\)/',$string,$array_match)) { for ($a = 0; $a < count($array_match[0]); $a++) { $word = preg_quote($array_match[0][$a],'('); if (key_exists($array_match[0][$a],$this->variable_main)) { $string = preg_replace("/$word/",$this->variable_main[$array_match[0][$a]],$string); } } } if (preg_match('//',$string,$var_array)) { $block_ = $var_array[1]; //получаем переменные(запрос, базовые настройки) из базы для блока $query = $my_engine_base->get_rowset('blocks','*',' where name = \''.$block_.'\' limit 1'); $this->block_template[$block_]['block_var'] = $query; $tr_fl = $this->load_block_template($block_,ROOT_PATH.'/template/'.$theme.'/templ/'.$query['data'][0]['template'],$theme); //if ($tr_fl) //{ // $this->block_template[$block_]['block_var'] = $query; //} $precomp_code[] = $string; } elseif (preg_match('/#{(.*)}=(.*);/',$string,$var_array)) { $this->variable_block[$block]['@('.$var_array[1].')']=$var_array[2]; } elseif (preg_match('/@{(.*)}=(.*);/',$string,$var_array)) { $this->variable_main[':('.$var_array[1].')']=$var_array[2]; } else { if (preg_match_all("/@\([^(.+)\)]+\)/",$string,$array_match)) { for ($a = 0; $a < count($array_match[0]); $a++) { $word = preg_quote($array_match[0][$a],'('); if (key_exists($array_match[0][$a],$this->variable_block[$block])) { $string = preg_replace("/$word/",$this->variable_block[$block][$array_match[0][$a]],$string); } } } $precomp_code[] = $string; } } $this->block_template[$block]['source_code'] = $precomp_code; $this->load_data_block($block,$this->block_template[$block]); $this->parse_template($block,$this->block_template[$block]); return true; } else { $this->block_template[$block]['source_code'][] = 'указанного блока несуществует'; $this->block_template[$block]['compiled_code'][] = 'указанного блока несуществует'; $this->parse_template($block,$this->block_template[$block]); header("HTTP/1.0 404 Not Found"); //указанного блока нет return false; } } function load_header_var() { global $my_engine_base,$current_config,$config_engine; //определяеи тайтл для выводимой страницы if ($current_config['DEFAULT_BLOCK']=='meta_form') { $row = $my_engine_base->get_rowset('title_page','*',"where block = '".$_GET['block']."'"); $source_id = $_GET['id']; } else { $row = $my_engine_base->get_rowset('title_page','*',"where block = '".$current_config['DEFAULT_BLOCK']."'"); $source_id = $current_config['ITEM']; } $cur_title = ''; if (is_array($row['data'])) { foreach ($row['data'] as $val) { if ((trim($val['title'])!='') and ($val['item']=='index')) { $cur_title = base64_decode($val['title']); } if ((trim($val['title'])!='') and ($val['item']==$current_config['ITEM'])) { $cur_title = base64_decode($val['title']); break; } } } if ($cur_title != '') { $this->variable_main[':(TITLE_PAGE)']=$cur_title; } //определяем текущие описание и ключевые слова $cur_descr =''; $cur_keyw = ''; if ($current_config['DEFAULT_BLOCK']=='meta_form') { $row = $my_engine_base->get_rowset('meta_page','*',"where block = '".$_GET['block']."' and item='".$_GET['id']."' limit 1"); $source_id = $_GET['id']; } else { $row = $my_engine_base->get_rowset('meta_page','*',"where block = '".$current_config['DEFAULT_BLOCK']."' and item='".$current_config['ITEM']."' limit 1"); $source_id = $current_config['ITEM']; } if (is_array($row['data'])) { foreach ($row['data'] as $val) { $cur_descr = base64_decode($val['description']); $cur_keyw = base64_decode($val['keywords']); } } $this->variable_main[':(DESCRIPTION)']=$cur_descr!=''?$cur_descr:''; $this->variable_main[':(KEYWORDS)']=$cur_keyw!=''?$cur_keyw:''; //определяем стили для страницы $style_link = ''; if (is_dir(ROOT_PATH.'/template/'.$config_engine['DEFAULT_THEME'].'/styles/')) { $dir = ROOT_PATH.'/template/'.$config_engine['DEFAULT_THEME'].'/styles/'; if ($dh = opendir($dir)) { $sep = ''; while (($file = readdir($dh)) !== false) { if (is_file($dir.'/'.$file)) { @$style_link .= $sep.''; $sep = "\n"; } } closedir($dh); } } $this->variable_main[':(LINK_STYLE)']=$style_link!=''?"\r\n".$style_link:''; } function load_lang($lang) { global $my_engine_base; $data = $my_engine_base->get_rowset('translate','*',' where lang = \''.$lang.'\''); if (is_array($data['data'])) { foreach ($data['data'] as $value) { $this->set_var(array('L_'.$value['var']=>$value['value']),'language'); } } } } } ?>[phpBB Debug] PHP Notice: in file /srv/www/htdocs/alpacawool/index.php on line 136: Cannot modify header information - headers already sent by (output started at /srv/www/htdocs/alpacawool/includes/template_engine.php:143)